<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>后台管理 - 易买网</title>
    <link type="text/css" rel="stylesheet" href="../css/style.css"/>
    <script type="text/javascript" src="../scripts/function-manage.js"></script>
    <script type="text/javascript" src="../scripts/jquery-1.8.3.js"></script>
</head>
<body>
<div class="main">
    <h2>新增用户</h2>
    <div class="manage">
        <form action="../AddUserServlet" method="post">
            <table class="form">
                <tr>
                    <td class="field">用户名:</td>
                    <td><input type="text" class="text" name="username" value=""/></td>
                </tr>
                <tr>
                    <td class="field">姓名:</td>
                    <td><input type="text" class="text" name="userusername" value=""/></td>
                </tr>
                <tr>
                    <td class="field">密码:</td>
                    <td><input type="text" class="text" name="userpwd" value=""/></td>
                </tr>
                <tr>
                    <td class="field">性别:</td>
                    <td><input type="radio" name="sex" value="1" checked="checked"/>男 <input type="radio"
                                                                                             name="sex"
                                                                                             value="1"/>女
                    </td>
                </tr>
                <tr>
                    <td align="right">出生日期:</td>
                    <td><select id="birth_year" onchange="setDays(this,birth_month,birth_day);">
                        <option value="">年</option>

                    </select> <select id="birth_month" onchange="setDays(birth_year,this,birth_day);">
                        <option value="">月</option>

                    </select> <select id="birth_day">
                        <option value="">日</option>

                    </select></td>
                </tr>

                <tr>
                    <td class="field">邮箱:</td>
                    <td><input type="text" class="text" name="useremail" value=""/></td>
                </tr>
                <tr>
                    <td class="field">送货地址:</td>
                    <td><input type="text" class="text" name="useraddress" value=""/></td>
                </tr>
                <tr>
                    <td class="field">头像:</td>
                    <td><input type="file" class="text" name="photo"/></td>
                </tr>
                <tr>
                    <td class="field">权限:</td>
                    <td><input type="radio" name="userflag" value="1" checked="checked"/>普通用户 <input type="radio" name="userflag"value="1"/>管理员
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><label class="ui-blue"><input type="submit" name="submit" value="添加"/></label></td>
                </tr>
            </table>
        </form>
    </div>
</div>
</body>
</html>
<script>

    $(document).ready(function () {
        var i = -1;
        // 添加年份，从1910年开始
        for (i = 1910; i <= new Date().getFullYear(); i++) {
            addOption(birth_year, i, i - 1909);
            /*// 默认选中1988年
            if (i == 1988) {
                birth_year.options[i-1910].selected = true;
            }*/
        }
        // 添加月份
        for (i = 1; i <= 12; i++) {
            addOption(birth_month, i, i);
        }
        // 添加天份，先默认31天
        for (i = 1; i <= 31; i++) {
            addOption(birth_day, i, i);
        }


        //$("#birth_month"). birth_year  birth_day
    });


    // 设置每个月份的天数
    function setDays(year, month, day) {
        var monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        var yea = year.options[year.selectedIndex].text;
        var mon = month.options[month.selectedIndex].text;
        var num = monthDays[mon - 1];
        if (mon == 2 && isLeapYear(yea)) {
            num++;
        }
        for (var j = day.options.length - 1; j >= num; j--) {
            day.remove(j);
        }
        for (var i = day.options.length; i <= num; i++) {
            addOption(birth_day, i, i);
        }
    }

    // 判断是否闰年
    function isLeapYear(year) {
        return (year % 4 == 0 || (year % 100 == 0 && year % 400 == 0));
    }

    // 向select尾部添加option
    function addOption(selectbox, text, value) {
        var option = document.createElement("option");
        option.text = text;
        option.value = value;
        selectbox.options.add(option);
    }

</script>